package com.lkm.market2_0.m_imple.app_main;

import android.os.Handler;
import android.os.Looper;

import com.google.gson.annotations.SerializedName;
import com.lkm.frame.otto.LinkBus;
import com.lkm.frame.task2.ITaskExecutor;
import com.lkm.frame.task2.TaskManager;
import com.lkm.javatool.CollectionHelp;
import com.lkm.market2_0.entity.ResponEntity;
import com.lkm.market2_0.m.steelyarddata.OnBreedChangeEvent;
import com.lkm.market2_0.netapi.Api;
import com.lkm.market2_0.entity.BreedTo;
import com.lkm.market2_0.task.AsyncTask2;

import java.util.List;



public class LoadBreedForSTask extends AsyncTask2<String,String,ResponEntity<List<BreedTo> >> {

    public LoadBreedForSTask(ITaskExecutor<String, String, ResponEntity<List<BreedTo>>> taskExecutor,TaskManager mTaskManager) {
        super(taskExecutor, LoadBreedForSTask.class.getName(), mTaskManager);
    }

    @Override
    protected void doAsyncExecuting(String steelyardMac){
        ResponEntity<List<BTo>> re=ResponEntity.fromJson(
                Api.loadBreedByDeviceMac(steelyardMac,LoadBreedForSTask.this)
                ,new com.google.gson.reflect.TypeToken<List<BTo>>() {}.getType(),""
        );

        ResponEntity<List<BreedTo>> res=new ResponEntity(re);
        if(re.getData()!=null){
            if(!CollectionHelp.isEmpty(re.getData()))
            res.setData(re.getData().get(0).balance_breed);
        }

        complete(res);
    }

    @Override
    public void onFinish(ResponEntity<List<BreedTo>> listResponEntity) {
        super.onFinish(listResponEntity);
        if(listResponEntity.isSuccess()){
            LinkBus.sendBroadcast(new OnBreedChangeEvent(listResponEntity.getData()), new Handler(Looper.getMainLooper()));
        }
    }

    
//        if(re.isSuccess()&&re.getData()!=null) {





//            GoodsButtonInfoTo goodsButtonInfoTo=new GoodsButtonInfoTo(b.goods_name,b.price);





    public static class BTo{

        @SerializedName("balance_breed")
      public  List<BreedTo>  balance_breed;

    }
}
